#include "pm_engine_impl.hpp"
#include "pm_project_impl.hpp"
#include "pm_repository_impl.hpp"
#include "pm_trigger_impl.hpp"

/*---------------------------------------------------------------------------*/

namespace ProjectManager {

/*---------------------------------------------------------------------------*/


EngineImpl::~EngineImpl()
{
	for ( size_t i = 0; i < m_projects.size(); ++i )
		delete m_projects[i];
	for ( size_t i = 0; i < m_repositories.size(); ++i )
		delete m_repositories[i];
	for ( size_t i = 0; i < m_triggers.size(); ++i )
		delete m_triggers[i];
}


/*---------------------------------------------------------------------------*/


Project&
EngineImpl::newProject( const std::string& _name )
{
	m_projects.push_back( new ProjectImpl( _name ) );
	return *m_projects.back();
}


/*---------------------------------------------------------------------------*/


Repository&
EngineImpl::newRepository(
		const std::string& _name
	,	const std::string& _url
	,	const std::string& _username
	,	const std::string& _password
)
{
	m_repositories.push_back(
		new RepositoryImpl( _name, _url, _username, _password )
	);
	return *m_repositories.back();
}


/*---------------------------------------------------------------------------*/


Trigger&
EngineImpl::newTrigger(
		const Repository& _repository
	,	unsigned int _checkInterval
)
{
	m_triggers.push_back( new TriggerImpl( _repository, _checkInterval ) );
	return *m_triggers.back();
}


/*---------------------------------------------------------------------------*/


int
EngineImpl::getProjectsCount() const
{
	return m_projects.size();
}


/*---------------------------------------------------------------------------*/


Project&
EngineImpl::getProject( int _idx )
{
	return *m_projects.at( _idx );
}


/*---------------------------------------------------------------------------*/

} // namespace ProjectManager
